﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CNShapes;
using System.Drawing;

namespace CNPageEditor
{
    public class Action_ShowPointer : Action
    {
        #region Action methods

        /// <summary>
        /// We set up the action here.
        /// </summary>
        public override void initialize()
        {
        }

		/// <summary>
		/// Called when the action becomes inactive.
		/// </summary>
		public override void deactivate()
		{
		}

		/// <summary>
        /// Returns the readable description of the action.
        /// </summary>
        public override string getDescription()
        {
            return "Show pointer";
        }

        /// <summary>
        /// This action cannot be undone, as it is not a permament action.
        /// </summary>
        public override bool supportsUndo()
        {
            return false;
        }

        /// <summary>
        /// The action is repeatable.
        /// </summary>
        public override bool isRepeatable()
        {
            return true;
        }

        // Undo and redo are not supported.
        public override void undo()
        {
        }
        public override void redo()
        {
        }

        /// <summary>
        /// Called when we receive a touch-down event.
        /// </summary>
        public override void onTouchDown(BobcatMultiTouch.TouchArgs touchArgs)
        {
            // We create the shape we'll be managing and add it to the page...
            m_Shape = new Shape_Pointer();
            m_Page.addShape(m_Shape, getActionOrigin());
            PointF pointerPosition = m_PageViewerControl.clientPointToShapePoint(touchArgs.ClientPosition);
            m_Shape.setPointerPosition(pointerPosition, getActionOrigin());
        }

        /// <summary>
        /// Called when we receive a touch-move event.
        /// </summary>
        public override void onTouchMove(BobcatMultiTouch.TouchArgs touchArgs)
        {
            PointF pointerPosition = m_PageViewerControl.clientPointToShapePoint(touchArgs.ClientPosition);
            m_Shape.setPointerPosition(pointerPosition, getActionOrigin());
        }

        /// <summary>
        /// Called when we receive a touch-down event.
        /// </summary>
        public override void onTouchUp(BobcatMultiTouch.TouchArgs touchArgs)
        {
            // The action has completed...
            m_Page.removeShape(m_Shape.ID, getActionOrigin());
            raiseActionCompletedEvent();
        }

        #endregion

        #region Private data

        private Shape_Pointer m_Shape = null;

        #endregion
    }
}
